/**
 * Created by ZY on 2018/05/13
 */
let _ = require('lodash'),
  util = require('../helper/util'),
  errCode = require('../../conf/errorCode'),
  logger = require('../helper/logger'),
  service = require('../services/pollService');

var tagLogger = new logger.TagLogger('COMMENT_CONTROLLER');

exports.getPollRelByPollId = function(req, res, next) {
  let {pollId} = req.params;
  service.getPollRelByPollId(
    pollId,
    util.getHandle(req, res, errCode.GET_POLL_REL_BY_POLLID),
  );
};

exports.getPollByPostIdAndUid = function(req, res, next) {
  let {postId} = req.query,
    {uid} = req.api_user;
  service.getPollByPostIdAndUid(
    postId,
    uid,
    util.getHandle(req, res, errCode.GET_POLL_BY_POSTID),
  );
};

exports.getPollByPostId = function(req, res, next) {
  let {postId} = req.query;
  service.getPollByPostId(
    postId,
    util.getHandle(req, res, errCode.GET_POLL_BY_POSTID),
  );
};

exports.add = function(req, res, next) {
  let {question, endAt, postId, choice} = req.body;

  service.add(
    question,
    endAt,
    postId,
    choice,
    util.getHandle(req, res, errCode.ADD_POLL),
  );
};
